package com.irs.irsforum.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import lombok.Data;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;
import java.util.Collection;

/**
 * <p>
 * 
 * </p>
 *
 * @author yihuili
 * @since 2020-02-15
 */
@Data
@TableName("forum_user")
public class User extends Model<User> implements Authentication{

    private static final long serialVersionUID = 1L;

	@TableId(value="id", type= IdType.AUTO)
	private Long id;
	@TableField("origin_id")
	private Long originId;
	private String role;
    /**
     * 昵称
     */
	private String nickName;
    /**
     * 邮箱地址
     */
	private String email;
    /**
     * 手机号
     */
	private String phone;

	private Boolean isAuthenticated;

	public User(Long originId, String role, String nickName, String email, String phone)

	{
		this.originId = originId;
		this.role = role;
		this.nickName = nickName;
		this.email = email;
		this.phone = phone;
	}

	public User() {
	}

	public User(Long id, String nickName, String email) {
		this.id = id;
		this.nickName = nickName;
		this.email = email;
	}

	public User(Long originId, String role) {
		this.originId = originId;
		this.role = role;
	}


	@Override
	public String getName() {
		return null;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}

	@Override
	public Object getCredentials() {
		return null;
	}

	@Override
	public Object getDetails() {
		return null;
	}

	@Override
	public Object getPrincipal() {
		return null;
	}

	@Override
	public boolean isAuthenticated() {
		if (this.isAuthenticated == null) {
			return false;
		} else {
			return this.isAuthenticated;
		}
	}

	@Override
	public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
		if (null != this.isAuthenticated) {
			return;
		}
		this.isAuthenticated = isAuthenticated;
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

	@Override
	public String toString() {
		return "ForumUser{" +
			"id=" + id +
			", originId=" + originId +
			", role=" + role +
			", nickName=" + nickName +
			", email=" + email +
			", phone=" + phone +
			"}";
	}


}
